﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xceed.Wpf.AvalonDock.Layout;

namespace CPPEI.Coolzon.Designer.Views
{
    public static class ShowOrHideViewCommand
    {
        public static void Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var view = UIContext.Current.DockingManager.Layout.Descendents().OfType<LayoutAnchorable>().Single(a => string.Equals(a.ContentId , e.Parameter));
            if(view != null)
            {
                if (view.IsHidden)
                {
                    view.Show();
                }
                else if (view.IsVisible)
                {
                    view.Hide();
                }
                else
                {
                    view.AddToLayout(UIContext.Current.DockingManager, AnchorableShowStrategy.Left | AnchorableShowStrategy.Most);
                }
            }
        }
        public static void CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (UIContext.Current.DockingManager != null)
                e.CanExecute = true;
        }
    }
}
